$().ready(function(){
    // 事件绑定
    InitPageEvent();
    // 页面初始化
    InitPageInfo();
});

/**
 * 事件绑定
 */
function InitPageEvent(){
	$("#submitButton").click(SubmitInvest);
}

/**
 * 页面初始化
 */
function InitPageInfo(){
	
}

/**
 * 提交问卷
 * @param {Object} e
 */
function SubmitInvest(e){
	var ansjson = getJsonData();
	$.post(serverPath + "/Invest/SubmitInvest", {
		Action : "post",
		AnsJson:ansjson,
		MainID:$(this).attr("CID")
	}, function(data, textStatus) {
		if (!data.success) {
				alert(data.message);
			} else {
				alert("您已提交成功，谢谢您的帮助！");
				document.location.href = "/Invest";
			}
	}, "json");
}

function getJsonData(){
	var ans = "[";
	$(".invest-quest .questionBox").each(function(index, obj) {
		ans += "{\"investquesid\":\""+$.trim($(obj).attr("QID")) + "\",";
		var tmp="";
		$(obj).find("input.option:checked").each(function(i, o){
			tmp += $.trim($(o).attr("OID"))+",";
        });
		tmp = tmp.length>0 ? tmp.substring(0, tmp.length - 1) : "";
		ans+= "\"anscontent\":\""+tmp + "\"},";
	});
	ans = ans.substring(0, ans.length - 1) + "]";
	return ans;
}
